package activities;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.evaluity.R;

import logic.Course;
import logic.Degree;
import logic.Test;
import data.DATA_Helper;
import android.os.Bundle;
import android.app.ListActivity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class CourseList extends ListActivity {

	protected static final String EXTRA_COURSE_ID = "course_id";
	protected static final String EXTRA_DEGREE_ID = "degree_id";
	
	private HashMap<Integer, Course> courseMap = new HashMap<Integer, Course>();
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_course_list);
		
		Intent i = getIntent();
		String degreeId = i.getStringExtra(EXTRA_DEGREE_ID);
		List<Course> courses = DATA_Helper.getcoursesByDegree(degreeId);
		List<String> couNames = new ArrayList<String>();
		
		for (int i1 = 0; i1 < courses.size(); i1++) {
			couNames.add(courses.get(i1).getName());
			courseMap.put(i1, courses.get(i1));
		}
		ArrayAdapter<String> courseAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, couNames);
		setListAdapter(courseAdapter);
	}
	
	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		Course c = courseMap.get(position);
		
		Intent i = new Intent(this, TestsList.class);
		i.putExtra(TestsList.EXTRA_COURSE_ID, c.getId());
		i.putExtra("offline", false);
		startActivity(i);
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.course_list, menu);
		return true;
	}

}
